
//Basic texture loading functions
//Matthew Bett 2006


#include "tex.h"

/*

//BitMap Loader.
AUX_RGBImageRec *LoadBitmap(char *name)
{
	FILE *File = NULL;			//Handle to the file

	if (!name)				//make sure a filename was given
	{
		return NULL;
	}

	File = fopen(name,"r"); //Opens the file with "read" access
						            	//just checks it actually exists.

	if (File)
	{
		fclose(File);					//close the file we opened.
		return auxDIBImageLoad(name);	// reads the data and returns a pointer
	}
	return NULL;

}

bool CreateGLTexture(char *name, GLuint & TexID )
{
	AUX_RGBImageRec *Texture[1];		//Creates storage space for the texture Width hieght info etc, and the data itself .
	memset(Texture,0,sizeof(void *)*1);	//makes sure the pointer is set to null.

	if(Texture[0]=LoadBitmap(name))	//Load in the bitmap. Checking the pointer is returned
	{
		//we are going to generate 1 texture and associate it with the Gluint ID we passes into this function.
		glGenTextures(1, &TexID);
		glBindTexture(GL_TEXTURE_2D, TexID); // binds the texture to a 2d type and to the TexID 

		//this huge line tells OpenGl to create a texture image using the file we loaded.
		//For full parameter listing check the openGL documentation.
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);// Linear Filtering
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);// Linear Filtering
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Texture[0]->sizeX, Texture[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, Texture[0]->data);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


		//free up the memory that stored the texture before openGL converted it
		free(Texture[0]->data); //the data
		free(Texture[0]);		//and the structure itself

		return true;
	}
	return false;
}
*/